<?php
    /*

     Version: MPL 1.1

     Software distributed under the License is distributed on an "AS IS"
     basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
     License for the specific language governing rights and limitations
     under the License.

     The Original Code is KASSIOP Framework.

     The Initial Developer of the Original Code is SURIAN Nicolas (aka NairuS) <me@nairus.fr>.
     Portions created by the Initial Developer are Copyright (C) 2010
     The Initial Developer. All Rights Reserved.

     Contributor(s):

     Alternatively, the contents of this file may be used under the terms
     of the MPL license Version 1.1 (the  "MPL" License"), in which case the
     provisions of Version: MPL 1.1 License are applicable instead of those
     above.  If you wish to allow use of your version of this file only
     under the terms of the MPL License and not to allow others to use
     your version of this file under the MPL, indicate your decision by
     deleting  the provisions above and replace  them with the notice and
     other provisions required by the MPL License.  If you do not delete
     the provisions above, a recipient may use your version of this file
     under either the MPL License.

     The contents of this file are subject to the Mozilla Public License
     Version 1.1 (the "License"); you may not use this file except in
     compliance with the License. You may obtain a copy of the License at
     http://www.mozilla.org/MPL/

    */


    require_once 'PHPUnit/Framework.php';
    require_once dirname( __FILE__ ) . '/../../../../kassiop/core/Autoload.php' ;
    Autoload::register() ;

    /**
     * The unit test class of the BooleanValidator class.
     *
     * @package unittests.kassiop.core
     * @subpackage controllers
     * @author NairuS
     *
     */
    class ControllerTest extends PHPUnit_Framework_TestCase
    {
        /**
         * Defines the model to test.
         *
         * @var ControllerClass
         */
        protected $controller ;

        /**
         * Defines the expected params in valid tests.
         *
         * @var array
         */
        protected $expectedParams ;

        protected function setUp()
        {
            $this->controller     = new ControllerClass( new Configuration( '/demos' ) ) ;
            $this->expectedParams = array('test' => 'test', 'file' => array( 'error' => UPLOAD_ERR_OK, 'name' => 'test.txt', 'size' => '10', 'tmp_name' => dirname( __FILE__ ) . '/samples/test.txt', 'type' => 'text/plain' ) );
        }

        protected function tearDown()
        {
            unset( $this->controller );
        }

        public function testGetAction()
        {
            $this->assertEquals( $this->controller->getAction(), 'index', 'The action to launch must be setted.' ) ;
        }

        public function testGetApplication()
        {
            $this->assertEquals( $this->controller->getApplication(), 'frontend', 'The application context must be setted.' ) ;
        }

        public function testGetModule()
        {
            $this->assertEquals( $this->controller->getModule(), 'demos', 'The module context must be setted.' ) ;
        }

        public function testGetFlashes()
        {
            $this->assertEquals( $this->controller->getFlashes(), array(), 'The flashes vars must be an empty array.' );
        }

        public function testSetFlashes()
        {
            $this->controller->setFlashes('Test message', FlashesVars::ERROR );
            $flashes = $this->controller->getFlashes();

            $this->assertFalse( empty($flashes ), 'The flashes vars must not be an empty array.' );
            $this->assertEquals( $flashes[FlashesVars::LEVEL], FlashesVars::ERROR, 'The level must be well setted.' );
            $this->assertEquals( $flashes[FlashesVars::MESSAGE], 'Test message', 'The message must be well setted.' );
        }

        public function testNoPostFile()
        {
           $this->assertEquals( array('test' => 'test'), $this->controller->noPostFile(), 'The action must return no post file.' );
        }

        public function testUnvalidPostFile()
        {
           $this->assertEquals( array('test' => 'test'), $this->controller->unvalidatePostFile(), 'The action must not return post file.' );
        }

        public function testValidPostFile()
        {
           $this->assertEquals( $this->expectedParams, $this->controller->validPostFile(), 'The action must return post file.' );
        }

        public function testValidPostFileWithTemp()
        {
            $this->expectedParams['temp_file'] = 'test.txt';
            $this->assertEquals( $this->expectedParams, $this->controller->validPostFileWithTemp(), 'The action must return post file with temp key.' );
        }
    }
?>
